<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document1</title>
</head>
<body>
    <div>test1</div>
    <script src="./sw.js"></script>
    <script>
        window.onload = function() {
            if ('serviceWorker' in navigator) {
              navigator.serviceWorker.register('./sw.js', { scope: '/' }).then(registration=>{
                console.log('ServiceWorker 注册成功！作用域为: ', registration.scope) 
              }).catch(err=>{
                console.log('ServiceWorker 注册失败: ', err)
              })
            }
        }
    </script>
</body>
</html>